<?php
class Paper_list_model extends MY_Model{
    
    function Paper_list_model(){
        parent::MY_Model();
        $this->bur_papers='bur_papers';
        $this->load->database();
    }

    	function total_paper_list() {
		$this->db->from($this->bur_papers);
	
		return $this->db->count_all_results();
	}    
    function list_paper_list($limit='false',$offset='false',$order_by=''){
    	if ($limit){
        	$limit = (int)$limit;
    		$offset = (int)$offset;
        }
		
		//$this->db->order_by('paper_id','DESC');
      switch($order_by){
			default:
            case 'order':
				$this->db->order_by("paper_id",'DESC');
				break;
			case 'paper':
				$this->db->order_by("paper_title",'DESC');
				break;
			case 'colour':
				$this->db->order_by("paper_colour",'DESC');
				break;
			case 'size':
				$this->db->order_by("paper_size",'DESC');
				break;
		}

		if ($limit){
            $query = $this->db->get($this->bur_papers,$limit,$offset);
        }else{
            $query = $this->db->get($this->bur_papers);
        }
  // echo $this->db->last_query();
      
    // $query=$this->db->get($this->bur_paperlist); 
    
     if($query->num_rows()>0){
        return $query->result_array();
        
     }else{
        return false;
        
     }
    }

    function get_paper_list_detail($paper_list_id=''){
		
		$this->db->where('paper_id',$paper_list_id);
	 	$query = $this->db->get($this->bur_papers);
		if($query->num_rows() > 0){
			return $query->row_array();
		}else{
			return FALSE;
		}
	}  
     function delete_paper_list($paper_list_id ){
        if(!empty($paper_list_id)){
            foreach($paper_list_id as $id):
            $this->db->where('paper_id',$id);
            $this->db->delete($this->bur_papers);
            endforeach;
        } else {
            return False;
            
        }  
        }
    function do_action(){
        
        if($this->input->post('paper_id'))
        {
           // echo 'edit';
           // echo $this->input->post('papersize_id');
           // echo $this->input->post('papersize_title');
            
            $this->db->set('paper_title',$this->input->post('paper_title'));
             $this->db->set('paper_colour',$this->input->post('paper_colour'));
              $this->db->set('paper_size',$this->input->post('paper_size'));
            $this->db->where('paper_id',$this->input->post('paper_id'));
            $this->db->update($this->bur_papers);
            
       }else{
           // echo 'add';
          $this->db->set('paper_colour',$this->input->post('paper_colour'));
           $this->db->set('paper_size',$this->input->post('paper_size'));
            $this->db->set('paper_title',$this->input->post('paper_title'));
          $this->db->insert($this->bur_papers);
            
      }
      
      
       // die();
    }
    function check_paper_title($str){
        
        $this->db->where('paper_title',$str);
        $query=$this->db->get($this->bur_papers);
        if($query->num_rows()>0){
            
            return True;
        }else{
            return false;
            
        }
        
    }
}
?>
